package dao

import (
	"wish_go/src/main/com/ajie/common"
	"wish_go/src/main/com/ajie/model"
	"wish_go/src/main/com/ajie/vo"
)

func PageActivity(activity *model.Activity, pagination *vo.Pagination) (rows []model.Activity, total int64, err error) {
	// 分页查询
	offset := (pagination.PageNum - 1) * pagination.PageSize
	db := common.GetDB()
	err = db.Model(&activity).Where(activity).Count(&total).Limit(pagination.PageSize).Offset(offset).Order(pagination.SortName).Find(&rows).Error
	return
}

func InsertActivity(activity model.Activity) (err error) {
	db := common.GetDB()
	// 添加数据
	err = db.Create(&activity).Error
	return
}

func UpdateActivity(activity model.Activity) (err error) {
	db := common.GetDB()
	// 更新数据
	err = db.Model(&activity).Select("title", "image", "update_name", "content", "grade").Updates(activity).Error
	return

}

func DeleteActivity(activity model.Activity) (err error) {
	db := common.GetDB()
	// 删除数据。根据主键删除--存在deleted_at 就软删除
	err = db.Delete(&activity).Error
	return
}
